Skip to content

feat(v2): open a box from OpenCode, in the terminal, the browser or the OpenCode app - #21

Open
tomasvarga wants to merge 2 commits into
mainfrom
feat/box-web
Open

tomasvarga wants to merge 2 commits into
mainfrom
feat/box-web

Conversation

@tomasvarga

Copy link
Copy Markdown
Collaborator

Follow-up to #18. Before this change, you had to quit OpenCode and run opencode-e2b box attach in a terminal to work in a box. Now you can reach a box from where you already are: your terminal, a browser, or the OpenCode app.

What

  • /e2b-attach [name] (new TUI plugin, src/v2/tui.ts): pauses your OpenCode and opens the box's TUI in the same terminal, the same way /editor works. Quit it (Ctrl+C) to come back. A toast says the box keeps working.
  • /e2b-box open [name] and opencode-e2b box open: a one-time sign-in link from opencode pair in the box. It opens the box's web UI signed in, and copies a second link for the OpenCode app (Settings > Servers > Add server). It also wakes a paused box.
  • /e2b-box up shows its progress, copies the sign-in link, and starts the box with your default model. The CLI takes --model <provider/model>.

Videos

Terminal: /e2b-box up, /e2b-attach, detach mid-task, attach again, /continue: the work is done. Then pull and kill.

box-tui.mp4

Browser: /e2b-box up copies the link; paste it in a browser.

box-browser.mp4

OpenCode app: /e2b-box up inside the app, then paste the link under Add server. The box shows next to your computer, with its own projects.

box-desktop.mp4

How it works

  • Background service in the box: the box now runs OpenCode as its background service (opencode2 service set ... + service start) instead of opencode2 serve, because opencode pair only makes links for the service.
  • Project registration: at start, the project is registered with GET /api/location, so the web UI shows it one click away.
  • Readiness check: waits for /api/info with the password, not the web page.
  • TUI plugin:
    • It is loaded from the new ./tui package export, from the same opencode.json entry. Users need no extra config.
    • Its command layer must use mode: "global". Otherwise the slash command does not show.
  • Links: each link works once, for 5 minutes, and sets a 30-day cookie. The box password is never shown. box/local.ts opens the browser and copies to the clipboard (pbcopy, wl-copy, xclip, clip), as a best effort; the link is always printed too.

Tested

  • bun run check: 103 tests. New tests cover reading the link from pair output and choosing the model.
  • Live on E2B (US):
    • TUI (OpenCode 2.3.2): up with progress, attach, detach mid-task, attach and /continue, pull, kill.
    • Browser: link → sign-in → agent commit.
    • OpenCode desktop app 2.3.2: the plugin loads there, then /e2b-box up, Add server, and a session in the box.
    • Earlier CLI flows: --server client, stop then open wakes the box, pull.
  • Clipboard: the link lands on the clipboard from the TUI and from the app.

Not in this PR

  • Short reply in the app: the app folds plugin replies into "Updates" rows, so only the short first line ("Sign-in link copied") shows until you open the row.
  • Box lists: boxes started in the desktop app are recorded in the app's own state folder, so the CLI's box list does not show them.
  • A second box in a box's web UI: adding it under Add server fails, probably because of CORS. The desktop app does not have this problem.
  • A one-click connect: this would need an opencode:// link in OpenCode to add a server. Version 2.3.2 does not have one.
  • From earlier: the handoff from shell mode to a box, and a dashboard.

- /e2b-attach (TUI plugin): suspends the TUI, runs the box's TUI in the same
  terminal, resumes on quit with a toast. Loaded from the ./tui export.
- /e2b-box open and opencode-e2b box open: one-time sign-in link from
  opencode pair in the box; opens the browser and copies a second link.
- The box runs OpenCode as its background service (pair needs it), opens the
  project for the web UI, and waits on the API with the password.
- /e2b-box up shows progress, copies the link, and passes the local default
  model; the CLI takes --model.
The OpenCode app folds plugin replies into rows that show about 80
characters, so the first line only says the link is copied.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants